package logic

import (
	"context"
	"rikao1/model/model"

	"rikao1/rikao1rpc/internal/svc"
	"rikao1/rikao1rpc/rikao1rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *rikao1rpc.AddRequest) (*rikao1rpc.AddResponse, error) {
	// todo: add your logic here and delete this line

	user := model.User{
		Phone:    in.Phone,
		Password: in.Password,
	}

	err := user.UserAdd(model.DB)
	if err != nil {
		return nil, err
	}

	return &rikao1rpc.AddResponse{
		UserId: int64(user.ID),
	}, nil
}
